import { createApp, type App as AppInstance } from 'vue'
import App from './App.vue'
import './style.css'
import router from './router';
import {
  renderWithQiankun,
  qiankunWindow
} from 'vite-plugin-qiankun/dist/helper';

let app: AppInstance | null = null;
function render(props: any = {}) {
  const { container } = props;
  app = createApp(App);
  app.use(router);
  app.mount(container ? container.querySelector('#app') : '#app');
}

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render();
}

renderWithQiankun({
  mount(props) {
    render(props);
  },
  bootstrap() {
    console.log('bootstrap');
  },
  unmount(props) {
    app?.unmount();
    app!._container.innerHTML = '';
    app = null;
  },
  update() {
    console.log('update');
  },
})

